import Vue from "vue";
import Vuex from "vuex";
import { getItem, setItem } from "@/utils/storage";
Vue.use(Vuex);

const TOKEN_KEY = "TOUTIAO_USER";
export default new Vuex.Store({
  state: {
    // 存储当前登录的用户 TOKEN_KEY 信息
    // user: JSON.parse(window.localStorage.getItem(TOKEN_KEY))
    user: getItem(TOKEN_KEY)
  },
  mutations: {
    async setUser(state, data) {
      state.user = data;
      // window.localStorage.setItem(TOKEN_KEY, JSON.stringify(state.user))
      await setItem(TOKEN_KEY, state.user);
    }
  },
  actions: {},
  modules: {}
});
